package cs304.p3.library.model;

import java.util.List;

import com.google.common.collect.Lists;

import cs304.p3.library.domain.Book;

public class BorrowerSearchForm {
	
	private String title, author, subject;
	private List<Book> results;
	
	public void setResult(List<Book> res){
		results = res;
	}
	
	public List<Book> getResults(){
		return results;
	}

	public List<String> getTitle() {
		List<String> titles = Lists.newArrayList();
		String[] splitTitles = title.split(",");
		for(int i=0; i<splitTitles.length; i++){
			if(splitTitles[i].isEmpty()) continue;
			splitTitles[i].trim();
			titles.add(splitTitles[i]);
		}
		return titles;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public List<String> getAuthor() {
		List<String> authors = Lists.newArrayList();
		String[] authorSplits = author.split(",");
		for(int i=0; i<authorSplits.length; i++){
			if(authorSplits[i].isEmpty()) continue;
			authorSplits[i].trim();
			authors.add(authorSplits[i]);
		}
		return authors;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public List<String> getSubject() {
		List<String> subjects = Lists.newArrayList();
		String[] subjectSplit = subject.split(",");
		for(int i=0; i<subjectSplit.length; i++){
			if(subjectSplit[i].isEmpty()) continue;
			subjectSplit[i].trim();
			subjects.add(subjectSplit[i]);
		}
		return subjects;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

}
